<?php

namespace XWAM\Addon\PXCallSystem\Model;

/**
 * MusicMenuModel数据库模型
 *
 * @author SoChishun <14507247@qq.com>
 * @version 1.0
 * @since 1.0.0 <2015-4-24> SoChishun Added.
 */
class MusicMenuModel extends AppbaseModel {

    /**
     * 数据表名称
     * @var string
     */
    protected $tableName = 'tcti_voice_menu';

    /**
     * 字段定义
     * @var array
     */
    protected $fields = array();

    /**
     * 命名范围
     * @var array
     */
    protected $_scope = array(
        'item_list' => array(
            'table'=>'tcti_voice_menu left join tgeneral_file on tcti_voice_menu.music=tgeneral_file.fileName',
            'field' => 'tcti_voice_menu.*, tgeneral_file.dirName',
            'order' => 'tcti_voice_menu.siteID, tcti_voice_menu.id desc',
            'group'
        ),);

    /**
     * 是否批量验证
     * @var boolean
     */
    protected $patchValidate = true;

    /**
     * 验证规则
     * @var array
     */
    protected $_validate = array();

    /**
     * 自动填充
     * @var array
     */
    protected $_auto = array();

    /**
     * 返回列表
     * @return array
     * @xince 1.0 <2015-6-9> SoChishun Added.
     */
    public function get_musicmenu_list($where) {
        $orderby = I('sort', $this->_scope['item_list']['order']) . ' ' . I('order');
        $page = I('page', 1) . ',' . I('rows', C('USER.PAGE_SIZE'));
        
        $list = AddonD('MusicMenu')->get_paging_list($where, $show, array('FIELDS' => 'tcti_voice_menu.*, tgeneral_file.dirName', 'ORDERBY' => 'tcti_voice_menu.siteID, tcti_voice_menu.id desc', 'TABLE' => 'tcti_voice_menu left join tgeneral_file on tcti_voice_menu.music=tgeneral_file.fileName', 'GROUPBY' => 'tcti_voice_menu.id','CACHE'=>3));
        $total = $this->cache(3)->where($where)->count('id');
        $list = $this->cache(3)->scope('item_list')->where($where)->order($orderby)->page($page)->select();
        $out = array();
        foreach ($list as $row) {
            $row['siteIDText'] = get_siteID_text($row['siteID']);
            $row['musicText']=ltrim($row['music'],'xcall_');
            $row['outEcEnableText']=sofn_get_state_text('yes-no',$row['outEcEnable']);
            $row['outOperText']=get_outOper_text($row['outOper']);
            $row['outParamText']=$row['outParam'].$row['outQueue'];
            $row['listenPath']=get_voc_url('sounds').$row['dirName'].'/'.$row['music'].'.wav';
            $row['downloadPath']=$row['listenPath'];
            $out[] = $row;
        }
        return array('total' => $total, 'rows' => $out);
    }

}
